//
//  buildViewController.m
//  Project
//
//  Created by iD Student on 7/30/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "buildViewController.h"

@interface buildViewController ()

@end

@implementation buildViewController
@synthesize resourceScollButton;
@synthesize resourceInfo;
@synthesize resourceScroll;
@synthesize woodCount;
@synthesize stoneCount;
@synthesize ironCount;
@synthesize woodLevel;
@synthesize stoneLevel;
@synthesize ironLevel;
@synthesize woodWCost;
@synthesize stoneWCost;
@synthesize ironWCost;
@synthesize woodSCost;
@synthesize stoneSCost;
@synthesize ironSCost;
@synthesize woodICost;
@synthesize stoneICost;
@synthesize ironICost;
@synthesize buildHelp;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
//    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
//    if (self) {
//        // Custom initialization
//    }
    return [self.storyboard instantiateViewControllerWithIdentifier:@"buildController"];
}

- (void)viewDidLoad
{
    resourceInfo.hidden = TRUE;
    resourceScollButton.hidden = TRUE;
    resourceScroll.hidden = TRUE;
    
    woodWCost.text = [NSString stringWithFormat:@"%d", woodW];
    woodSCost.text = [NSString stringWithFormat:@"%d", woodS];
    woodICost.text = [NSString stringWithFormat:@"%d", woodI];
    stoneWCost.text = [NSString stringWithFormat:@"%d", stoneW];
    stoneSCost.text = [NSString stringWithFormat:@"%d", stoneS];
    stoneICost.text = [NSString stringWithFormat:@"%d", stoneI];
    ironWCost.text = [NSString stringWithFormat:@"%d", ironW];
    ironSCost.text = [NSString stringWithFormat:@"%d", ironS];
    ironICost.text = [NSString stringWithFormat:@"%d", ironI];
    woodLevel.text = [NSString stringWithFormat:@"%d", woodLvl];
    stoneLevel.text = [NSString stringWithFormat:@"%d", stoneLvl];
    ironLevel.text = [NSString stringWithFormat:@"%d", ironLvl];
    
    [super viewDidLoad];
	// Do any additional setup after loading the view.
}

- (void)viewDidUnload
{
    [self setWoodCount:nil];
    [self setStoneCount:nil];
    [self setIronCount:nil];
    [self setWoodLevel:nil];
    [self setStoneLevel:nil];
    [self setIronLevel:nil];
    [self setWoodWCost:nil];
    [self setStoneWCost:nil];
    [self setIronWCost:nil];
    [self setWoodSCost:nil];
    [self setStoneSCost:nil];
    [self setIronSCost:nil];
    [self setWoodICost:nil];
    [self setStoneICost:nil];
    [self setIronICost:nil];
    [self setResourceScollButton:nil];
    [self setResourceInfo:nil];
    [self setResourceScroll:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

//- (void)dealloc {
//    [woodCount release];
//    [stoneCount release];
//    [ironCount release];
//    [woodLevel release];
//    [stoneLevel release];
//    [ironLevel release];
//    [woodWCost release];
//    [stoneWCost release];
//    [ironWCost release];
//    [woodSCost release];
//    [stoneSCost release];
//    [ironSCost release];
//    [woodICost release];
//    [stoneICost release];
//    [ironICost release];
//    [super dealloc];
//}
- (IBAction)back:(id)sender 
{
    [self dismissModalViewControllerAnimated:YES];
}
- (IBAction)woodUpgrade:(id)sender 
{
    if (resourcescroll == FALSE)
    {
        resourceInfo.hidden = FALSE;
        resourceScollButton.hidden = FALSE;
        resourceScroll.hidden = FALSE;
        resourcescroll = TRUE;
    }
    else 
    {
        if (wood >= woodW && stone >= woodS && iron >= woodI)
        {
            wood = wood - woodW;
            stone = stone - woodS;
            iron = iron - woodI;
            woodCount.text = [NSString stringWithFormat:@"%d", wood];
            stoneCount.text = [NSString stringWithFormat:@"%d", stone];
            ironCount.text = [NSString stringWithFormat:@"%d", iron];
        
            woodW = woodW + 1 + (w * 2);
            woodWCost.text = [NSString stringWithFormat:@"%d", woodW];
            woodS = woodS + (w * 3);
            woodSCost.text = [NSString stringWithFormat:@"%d", woodS];
            woodI = woodI - 1 + (w * 5);
            woodICost.text = [NSString stringWithFormat:@"%d", woodI];
        
            w++;
            woodLvl++;
            woodLevel.text = [NSString stringWithFormat:@"%d", woodLvl];
        }
    }
}

- (IBAction)stoneUpgrade:(id)sender 
{
    if (resourcescroll == FALSE)
    {
        resourceInfo.hidden = FALSE;
        resourceScollButton.hidden = FALSE;
        resourceScroll.hidden = FALSE;
        resourcescroll = TRUE;
    }
    else
    {
    if (wood >= stoneW && stone >= stoneS && iron >= stoneI)
    {
        wood = wood - stoneW;
        stone = stone - stoneS;
        iron = iron - stoneI;
        woodCount.text = [NSString stringWithFormat:@"%d", wood];
        stoneCount.text = [NSString stringWithFormat:@"%d", stone];
        ironCount.text = [NSString stringWithFormat:@"%d", iron];
        
        stoneW = stoneW + 1 +(s * 5);
        stoneWCost.text = [NSString stringWithFormat:@"%d", stoneW];
        stoneS = stoneS + 1+ (s * 2);
        stoneSCost.text = [NSString stringWithFormat:@"%d", stoneS];
        stoneI = stoneI - 1 + (s * 3);
        stoneICost.text = [NSString stringWithFormat:@"%d", stoneI];
        
        s++;
        stoneLvl++;
        stoneLevel.text = [NSString stringWithFormat:@"%d", stoneLvl];
    }
    }
}

- (IBAction)ironUpgrade:(id)sender 
{
    if (resourcescroll == FALSE) 
    {
        resourceInfo.hidden = FALSE;
        resourceScollButton.hidden = FALSE;
        resourceScroll.hidden = FALSE;
        resourcescroll = TRUE;
    }
    else
    {
    if (wood >= ironW && stone >= ironS && iron >= ironI)
    {
        wood = wood - ironW;
        stone = stone - ironS;
        iron = iron - ironI;
        woodCount.text = [NSString stringWithFormat:@"%d", wood];
        stoneCount.text = [NSString stringWithFormat:@"%d", stone];
        ironCount.text = [NSString stringWithFormat:@"%d", iron];
        
        ironW = ironW + (i * 3);
        ironWCost.text = [NSString stringWithFormat:@"%d", ironW];
        ironS = ironS - 3 + (i * 6);
        ironSCost.text = [NSString stringWithFormat:@"%d", ironS];
        ironI = ironI - 2 + (i * 3);
        ironICost.text = [NSString stringWithFormat:@"%d", ironI];
        
        i++;
        ironLvl++;
        ironLevel.text = [NSString stringWithFormat:@"%d", ironLvl];
    }
    }
}

- (IBAction)help:(id)sender 
{
    buildHelp = [self.storyboard instantiateViewControllerWithIdentifier:@"buildHelp"];
    [self presentModalViewController: buildHelp animated:YES];
}
- (void)dealloc {
    [resourceScollButton release];
    [resourceInfo release];
    [resourceScroll release];
    [super dealloc];
}
- (IBAction)scrollButton:(id)sender 
{
    resourceInfo.hidden = TRUE;
    resourceScollButton.hidden = TRUE;
    resourceScroll.hidden = TRUE;
}
@end
